﻿using CaterBll;
using CaterModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CaterUI
{
    public partial class FormLogin : Form
    {
        public FormLogin()
        {
            InitializeComponent();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            //this.Close();
            Application.Exit();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            Login();

        }

        private void btnLogin_KeyDown(object sender, KeyEventArgs e)
        { 

        }

        private void Login()
        {
            string name = txtName.Text;
            string pwd = txtPwd.Text;

            ManagerInfoBll miBll = new ManagerInfoBll();
            int type;
            LoginState loginState = miBll.Login(name, pwd, out type);

            switch (loginState)
            {
                case LoginState.Ok:
                    FormMain main = new FormMain();
                    main.Tag = type;
                    main.Show();
                    this.Hide();
                    break;
                case LoginState.NameError:
                    MessageBox.Show("用户名错误！");
                    break;
                case LoginState.PwdError:
                    MessageBox.Show("密码错误！");
                    break;
                default:
                    break;
            }
        }

        private void FormLogin_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyCode==Keys.Enter)
            {
                Login();
            }
        }

        private void FormLogin_Load(object sender, EventArgs e)
        {
            //设置窗体属性AcceptButton 为登录按钮，可实现回车登录
            //设置窗体属性CancelButton 为取消按钮，可实现ESC关闭

        }
    }
}
